#include "timing.h"

#include "error.h"
#include "utility/type.h"

#include <ctime>
#include <sys/time.h>
#include <type_traits>

namespace _ {

static_assert(std::is_same_v<Wrap::time_t_, time_t>, "time_t");

}

int Wrap::gettimeofday_(struct timeval *tv, struct timezone *tz) {
    return PERROR_NEQ0(::gettimeofday(tv, tz));
}

struct tm *Wrap::localtime_r_(const time_t_ *timer, struct tm *tp) {
    return PERROR_EQ0(::localtime_r(timer, tp));
}

int Wrap::setitimer_(int which, const struct itimerval *newValue, struct itimerval *oldValue) {
    return PERROR_NEQ0(::setitimer(which, newValue, oldValue));
}

Wrap::time_t_ Wrap::time_(time_t_ *timer) {
    return PERROR_NEG(::time(timer));
}
